package com.sf.fy.uav.applet.operate.controller;


import com.sf.fy.uav.applet.operate.service.ActivityService;
import com.sf.fy.uav.common.request.operate.WithdrawalRequest;
import com.sf.fy.uav.common.response.operational.CheckSigningResponse;
import com.sf.fy.uav.common.response.operational.RewardBillResponse;
import com.sf.fy.uav.common.response.operational.RewardBillRsResponse;
import com.sf.fy.uav.common.response.operational.RewardDetailsResponse;
import com.sf.fy.uav.common.utils.Rs;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;


/**
 * <p>
 * 活动表 前端控制器
 * </p>
 *
 * @author LTQ
 * @since 2023-08-16
 */
@RestController
@RequestMapping("/home/activity/")
@Tag(name = "活动相关", description = "活动相关")
public class ActivityController {

    @Autowired
    private ActivityService activityService;


    @GetMapping("reward/details")
    @Operation(tags = "获取奖励记录", description = "获取奖励记录")
    public Rs<RewardDetailsResponse> rewardDetails(@RequestParam Integer page, @RequestParam Integer size, @RequestParam String userId) {
        RewardDetailsResponse rewardDetailsResponse = activityService.rewardDetails(page, size, userId);
        Long total = activityService.rewardDetailsTotal(userId);
        rewardDetailsResponse.setTotal(total);
        return Rs.success(rewardDetailsResponse);
    }

    @GetMapping("reward/details/total")
    @Operation(tags = "获取奖励记录总条数", description = "获取奖励记录总条数")
    public Rs<Long> rewardDetailsTotal(@RequestParam String userId) {
        return Rs.success(activityService.rewardDetailsTotal(userId));
    }

    @GetMapping("get/bills")
    @Operation(tags = "获取账单记录", description = "获取账单记录")
    public Rs<RewardBillRsResponse> getBills(@RequestParam Integer page, @RequestParam Integer size, @RequestParam String userId) {
        RewardBillRsResponse rewardBillRsResponse = new RewardBillRsResponse();
        List<RewardBillResponse> rewardBillResponseList = activityService.getBills(page, size, userId);
        Long total = activityService.getBillsCount(userId);
        rewardBillRsResponse.setRewardBillResponseList(rewardBillResponseList);
        rewardBillRsResponse.setTotal(total);
        return Rs.success(rewardBillRsResponse);
    }

    @GetMapping("get/bills/count")
    @Operation(tags = "获取账单记录", description = "获取账单记录")
    public Rs<Long> getBillsCount(@RequestParam String userId) {
        return Rs.success(activityService.getBillsCount(userId));
    }

    @GetMapping("check/signing")
    @Operation(tags = "检查是否签约的接口", description = "检查是否签约的接口")
    public Rs<CheckSigningResponse> checkSigning(@RequestParam String userId) {
        return Rs.success(activityService.checkSigning(userId));
    }

    @PostMapping("withdrawal")
    @Operation(tags = "提现", description = "提现")
    public Rs<BigDecimal> withdrawal(@RequestBody @Validated WithdrawalRequest withdrawalRequest) {
        BigDecimal bigDecimal = activityService.withdrawal(withdrawalRequest);
        return Rs.success(bigDecimal);
    }

    @GetMapping("get/balance")
    @Operation(tags = "获取余额", description = "获取余额")
    @Parameter(name = "userId", description = "用户id")
//    public Rs<BigDecimal> getBalance(@RequestParam String userId) {
    public Rs<String> getBalance(@RequestParam String userId) {
        return Rs.success(activityService.getBalance(userId));
    }
}
